#ifndef XPMColorPicker_H
#define XPMColorPicker_H

#include <wx/scrolwin.h>
#include <wx/colour.h>
#include <wx/control.h>

#define XPM_MAX_COLOR 68
#define XPM_IDEAL_SIZE 16

class wxToggleButton;

BEGIN_DECLARE_EVENT_TYPES()
DECLARE_LOCAL_EVENT_TYPE( wxEVT_TRANSPARENT_COLOR_CHANGED, -1 )
DECLARE_LOCAL_EVENT_TYPE( wxEVT_LINE_COLOR_CHANGED, -1 )
DECLARE_LOCAL_EVENT_TYPE( wxEVT_FILL_COLOR_CHANGED, -1 )
END_DECLARE_EVENT_TYPES()

class XPMColorPicker : public wxPanel {
  public:
    XPMColorPicker( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
                    const wxSize& size = wxDefaultSize, int style = 0, const wxValidator &validator = wxDefaultValidator,
                    const wxString& name = _T( "XPMColorPicker" ) );
    ~XPMColorPicker();
    void init_colours( void );
    void Repaint( void );
    wxColour GetLineColour( void );
    wxColour GetFillColour( void );
    int GetLineColourIndex( void );
    int GetFillColourIndex( void );
    void SetLineColour( int iIndex, bool bPostEvent = true );
    void SetFillColour( int iIndex, bool bPostEvent = true );
    int GetPaletteSize( void );
    bool SetPaletteSize( int iSize );
    void SetPaletteColour( int iIndex, wxColour cColor );
    wxColour GetPaletteColour( int iIndex );
    wxColour GetTransparentColour( void );
    void SetTransparentColour( wxColour cColour, bool bPostEvent = true );
    virtual wxSize DoGetBestSize( void ) const;
  protected:
    void OnEventPaint( wxPaintEvent& event );
    void OnEventSize( wxSizeEvent& event );
    void OnToggleButton1Toggle( wxCommandEvent& event );
    void OnMouseEnter( wxMouseEvent& event );
    void OnMouseLeave( wxMouseEvent& event );
    void OnSetCursor( wxSetCursorEvent& event );
    void OnMouseDClick( wxMouseEvent& event );
    void OnMouseClick( wxMouseEvent& event );
    void OnMouseRClick( wxMouseEvent& event );
    int GetColourIndex( int x, int y );
    wxToggleButton* ToggleButton1;
    static const long ID_TOGGLEBUTTON1;
  private:
    wxColour *ColourArray;
    int iPaletteSize;
    int iColourWidth;
    int iColourHeight;
    int iHeight;
    int iWidth;
    int iNbRows;
    void ComputeDimensions( wxSize s );
    int iLineColor;
    int iFillColor;
    wxColour cTransparent;
    bool bLineOn;
    void Paint( wxDC *dc );

};

#endif
